using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

namespace Janus.NorthwindDemo2007
{
	public partial class ProductDataControl
	{

		protected override void OnDataSourceChanged()
		{
			if (DataSource != null)
			{
				this.editCategories.DropDownDataSource = NorthwindApp.NorthwindApplication.GetProductCategoryList();
				this.editCategories.ValuesDataMember = "Products.ProductsProduct_Categories";
				this.editCategories.ValuesDataSource = DataSource;

				this.grdSuppliers.DropDowns["Suppliers"].SetDataBinding(NorthwindApp.NorthwindApplication.GetSupplierList(), "");
				this.grdSuppliers.SetDataBinding(DataSource, "Products.ProductsSuppliers_Products");
			}
			this.AddBinding(this.lblProductID, "Text", "Products.ProductID");
			this.AddBinding(this.editDiscontinued, "BindableValue", "Products.Discontinued");
			this.AddBinding(this.editOnSale, "BindableValue", "Products.OnSale");
			this.AddBinding(this.editProductName, "Text", "Products.ProductName");
			this.AddBinding(this.editQuantityPerUnit, "Text", "Products.QuantityPerUnit");
			this.AddBinding(this.editReorderLevel, "Value", "Products.ReorderLevel");
			this.AddBinding(this.editUnitPrice, "Value", "Products.UnitPrice");
			this.AddBinding(this.editUnitsInStock, "Value", "Products.UnitsInStock");
			this.AddBinding(this.editUnitsOnOrder, "Value", "Products.UnitsOnOrder");

		}

		protected override void OnAllowEditChanged()
		{

			this.editDiscontinued.AutoCheck = this.AllowEdit;
			this.editOnSale.AutoCheck = this.AllowEdit;

			this.editCategories.ReadOnly = ! this.AllowEdit;
			this.editProductName.ReadOnly = ! this.AllowEdit;
			this.editQuantityPerUnit.ReadOnly = ! this.AllowEdit;
			this.editReorderLevel.ReadOnly = ! this.AllowEdit;
			this.editUnitPrice.ReadOnly = ! this.AllowEdit;
			this.editUnitsInStock.ReadOnly = ! this.AllowEdit;
			this.editUnitsOnOrder.ReadOnly = ! this.AllowEdit;
			if (this.AllowEdit)
			{
				this.grdSuppliers.AllowAddNew = Windows.GridEX.InheritableBoolean.True;
				this.grdSuppliers.AllowDelete = Windows.GridEX.InheritableBoolean.True;
				this.grdSuppliers.AllowEdit = Windows.GridEX.InheritableBoolean.True;
			}
			else
			{
				this.grdSuppliers.AllowAddNew = Windows.GridEX.InheritableBoolean.False;
				this.grdSuppliers.AllowDelete = Windows.GridEX.InheritableBoolean.False;
				this.grdSuppliers.AllowEdit = Windows.GridEX.InheritableBoolean.False;
			}
		}


		public override Size FullSize
		{
			get
			{
				return new System.Drawing.Size(576, 248);
			}
		}

		protected override void OnUseTabBackgroundChanged()
		{
			if (this.UseTabBackground)
			{
				this.gbBackground.BackgroundStyle = Windows.EditControls.BackgroundStyle.TabPage;
			}
			else
			{
				this.gbBackground.BackgroundStyle = Windows.EditControls.BackgroundStyle.Panel;
			}
		}


		private void grdSuppliers_CellUpdated(object sender, Janus.Windows.GridEX.ColumnActionEventArgs e)
		{
			if (e.Column.Key == "SupplierID" || e.Column.Key == "SupplierName")
			{
				grdSuppliers.SetValue("SupplierID", grdSuppliers.GetValue(e.Column));
				grdSuppliers.SetValue("SupplierName", grdSuppliers.GetValue(e.Column));

			}
		}
	}

} //end of root namespace